package com.hu.controller;


import com.hu.entity.Student;
import com.hu.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HU
 * @since 2019-03-01
 */
@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/index")
    @ResponseBody
    public Object index(){
        return studentService.list();
    }

    @RequestMapping("/student")
    public String student(Model model){
        List<Student> list = studentService.list();
        model.addAttribute("stuList",list);
        return "index";
    }

    @GetMapping("/upStu")
    public String uoStu(@RequestParam("id")int id, Model model){
        Student student = studentService.getById(id);
        model.addAttribute("student",student);
        return "student";
    }
    @PostMapping("/upStu")
    public String uoStu(Student student){

        return "index";
    }
}
